package org.syyo.admin.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.syyo.admin.anno.CheckPermissions;
import org.syyo.admin.anno.SysLog;
import org.syyo.admin.domain.ResultVo;
import org.syyo.admin.domain.request.MenuReq;
import org.syyo.admin.service.MenuService;

/**
 * @Auther: wangzhong
 * @Date: 2019/10/8 16:55
 * @Description: 菜单模块
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @SysLog("菜单添加")
    @CheckPermissions("system:menu:add")
    @PostMapping("/add")
    public ResultVo addMenu(@RequestBody MenuReq req){

        return menuService.addMenu(req);
    }

    @SysLog("菜单删除")
    @CheckPermissions("system:menu:del")
    @PostMapping("/del")
    public ResultVo delMenu(@RequestBody MenuReq req){
        return menuService.delMenu(req);
    }

    @SysLog("菜单编辑")
    @CheckPermissions("system:menu:edit")
    @PostMapping("/edit")
    public ResultVo editMenu(@RequestBody MenuReq req){
        return menuService.editMenu(req);
    }

    /**
     * 菜单详情
     * @param menuId
     * @return
     */
    @CheckPermissions("system:menu:index")
    @GetMapping
    public ResultVo getMenu(@RequestParam("menuId") Integer menuId){
        return menuService.getMenu(menuId);
    }


    /**
     * 菜单列表
     * @param req
     * @return
     */
    @CheckPermissions("system:menu:index")
    @GetMapping("/list")
    public ResultVo listMenu(MenuReq req){
        return menuService.listMenu(req);
    }

    /**
     * 菜单列表（树形结构）
     * @param req
     * @return
     */
    @CheckPermissions("system:menu:index")
    @GetMapping("/tree")
    public ResultVo treeMenu(MenuReq req){
        return menuService.treeMenu(req);
    }

}
